﻿// SLF.NET - Simple Logging Façade for .NET
// Contact and Information: http://slf.codeplex.com
//
// This library is free software; you can redistribute it and/or
// modify it in any way you see fit as long as this copyright
// notice is not being removed.
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// THIS COPYRIGHT NOTICE MAY NOT BE REMOVED FROM THIS FILE



using System;
using System.Collections.Generic;
using System.Linq;

namespace Slf
{
  /// <summary>
  /// Extension methods which are specific to SLF Silverlight.
  /// </summary>
  public static class Extensions
  {
    /// <summary>
    /// Searches for an element that matches the conditions defined by
    /// the specified predicate, and returns the first occurrence
    /// within the entire list. This extension adds support
    /// for <c>List.Find</c> in Silverlight.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="list">The inspected list.</param>
    /// <param name="predicate">A <see cref="Predicate{T}"/> delegate
    /// that defines the conditions of the element to search for.</param>
    /// <returns>The first element that matches the conditions defined by
    /// the specified predicate, if found; otherwise, the default value
    /// for type T.</returns>
    public static T Find<T>(this List<T> list, Predicate<T> predicate)
    {
      return list.FirstOrDefault(item => predicate(item));
    }
  }
}
